package controle;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;



	
public class Conexao {  
	  private static Connection conn;  
	    
	  public static void abrir(String driver, String url, String usuario, String senha) {  
	    try {  
	      Class.forName(driver);  
	      conn = DriverManager.getConnection(url, usuario, senha);  
	    }  
	    catch (Exception e) {  
	      e.printStackTrace();  
	    }  
	  }  
	    
	  public static Connection obter() {  
	    return conn;  
	  }  
	  public static String getAutoInc(String Generator) {  
	        String value = "";  
	        try {  
	            PreparedStatement pstmt = conn.prepareStatement("" +  
	                    "Select Gen_Id(" + Generator + ",1) as Codigo From RDB$DataBase");  
	            ResultSet rs = pstmt.executeQuery();  
	            rs.next();  
	            value = rs.getString("Codigo");  
	            rs.close();  
	            pstmt.close();  
	        }  
	        catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	        return value;  
	    }  
	  
	}  


		
	


